package com.njtoyo.taxi.admin.rest.controller.local_service.merchant;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mapper.master.entity.local_service.LifeAddress;
import com.njtoyo.taxi.admin.mapper.master.entity.local_service.LifeMerchant;
import com.njtoyo.taxi.admin.rest.presenter.local_service.merchant.LifeAddressPresenter;
import com.njtoyo.taxi.admin.rest.presenter.local_service.merchant.LifeMerchantDetailsPresenter;
import com.njtoyo.taxi.admin.rest.presenter.local_service.merchant.LifeMerchantPagePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.merchant.*;
import com.njtoyo.taxi.admin.service.local_service.merchant.MerchantService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "现有商户管理", tags = "现有商户管理")
@RequestMapping("local-service/merchant")
public class MerchantController {

    @Autowired
    private MerchantService lifeMerchantService;

    @GetMapping("/all")
    @ApiOperation(value = "所有现有商户列表", notes = "所有现有商户列表,权限：")
    RestResult<List<LifeMerchant>> all(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser) {
        return lifeMerchantService.all(adminUser);
    }
    @GetMapping("/all/{driverRegionId}")
    @ApiOperation(value = "司机运营区下商户列表", notes = "司机运营区下商户列表,权限：")
    RestResult<List<LifeMerchant>> allBydriverRegionId(@PathVariable("driverRegionId") Long  driverRegionId) {
        return lifeMerchantService.allBydriverRegionId(driverRegionId);
    }

    @GetMapping("")
    @ApiOperation(value = "现有商户列表", notes = "现有商户列表,权限：life_merchant_list")
    @PermissionScope(names = {"life_merchant_list"})
    RestResult<Page<LifeMerchantPagePresenter>> getPage(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                                                        @Valid LifeMerchantQueryWrapper wrapper) {
        return lifeMerchantService.getPage(adminUser, wrapper);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "现有商户详情", notes = "添加现有商户,权限:life_merchant_list")
    @PermissionScope(names = {"life_merchant_list"})
    RestResult<LifeMerchantDetailsPresenter> details(@PathVariable("id") Long id) {
        return lifeMerchantService.details(id);
    }

    @PostMapping("")
    @ApiOperation(value = "添加现有商户", notes = "添加现有商户,权限:life_merchant_add")
    @PermissionScope(names = {"life_merchant_add"})
    RestResult add(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                   @Valid @RequestBody LifeMerchantAddWrapper wrapper) {
        return lifeMerchantService.add(adminUser, wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "修改商户", notes = "life_merchant_update")
    @PermissionScope(names = {"life_merchant_update"})
    RestResult update(@PathVariable("id") Long id,
                      @Valid @RequestBody LifeMerchantUpdateWrapper wrapper) {
        return lifeMerchantService.update(id, wrapper);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除商品商户", notes = "life_merchant_delete")
    @PermissionScope(names = {"life_merchant_delete"})
    RestResult delete(@PathVariable("id") Long id) {
        return lifeMerchantService.delete(id);
    }

    @GetMapping("/{id}/pickup-location")
    @ApiOperation(value = "商户下自提点列表", notes = "自提点列表,权限：life_pickup_list")
    @PermissionScope(names = {"life_pickup_list"})
    RestResult<List<LifeAddress>> getSelfPage(@PathVariable("id") Long id) {
        return lifeMerchantService.getSelfPage(id);
    }

    @GetMapping("/{id}/no-pickup-location")
    @ApiOperation(value = "不属于这个商户的自提点列表", notes = "不属于这个商户的自提点列表,权限：life_pickup_list")
    @PermissionScope(names = {"life_pickup_list"})
    RestResult<List<LifeAddress>> noBelongPickup(@PathVariable("id") Long id) {
        return lifeMerchantService.noBelongPickup(id);
    }

    @PostMapping("/{id}/pickup-location")
    @ApiOperation(value = "商户自提点添加", notes = "商户自提点添加,权限：life_merchant_account_set_address")
    @PermissionScope(names = {"life_merchant_account_set_address"})
    RestResult addSelf(@PathVariable("id") Long id,
                       @Valid @RequestBody PickupLocationAddWrapper wrapper) {
        return lifeMerchantService.addSelf(id, wrapper);
    }

    @PostMapping("/{id}/pickup-locations")
    @ApiOperation(value = "商户添加多个自提点", notes = "设置自提点,权限：life_merchant_account_set_address")
    @PermissionScope(names = {"life_merchant_account_set_address"})
    RestResult addSelfs(@PathVariable("id") Long id,
                        @Valid @RequestBody PickupLocationAddsWrapper wrapper) {
        return lifeMerchantService.addSelfs(id, wrapper);
    }

    @GetMapping("/{id}/all-address")
    @ApiOperation(value = "商户下所有的地址", notes = "商户下所有的地址,权限：life_pickup_list")
    @PermissionScope(names = {"life_pickup_list"})
    RestResult<List<LifeAddressPresenter>> address(@PathVariable("id") Long id) {
        return lifeMerchantService.address(id);
    }

    @GetMapping("/pickup-location-page")
    @ApiOperation(value = "自提点分页列表展示", notes = "自提点分页列表展示,权限：life_pickup_list")
    @PermissionScope(names = {"life_pickup_list"})
    RestResult<Page<LifeAddress>> pickUpPage(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                                             @Valid PickupLocationPageWrapper wrapper) {
        return lifeMerchantService.pickUpPage(adminUser, wrapper);
    }

    @GetMapping("/pickup-location-list")
    @ApiOperation(value = "自提点不分页列表展示", notes = "自提点不分页列表展示,权限：life_pickup_list")
    @PermissionScope(names = {"life_pickup_list"})
    RestResult<List<LifeAddress>> pickUplist(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser) {
        return lifeMerchantService.pickUplist(adminUser);
    }

    @PostMapping("/pickup-location/setUp")
    @ApiOperation(value = "设置自提点", notes = "设置自提点,权限：life_pickup_add")
    @PermissionScope(names = {"life_pickup_add"})
    RestResult setUp(@Valid @RequestBody PickupLocationSetUpAddWrapper wrapper) {
        return lifeMerchantService.setUp(wrapper);
    }


}